/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "MudItem.h"
#include "CmdVisitor.h"
#include "StringBuilder.h"
#include "ItemDb.h"

using namespace Chronos;
using namespace std;

MudItem::MudItem(int type_, const string& name_, const string& descr_, int weight_)
    : MudObject(name_, descr_)
    , weight(weight_)
    , type(type_)
{}


MudItem::MudItem(const MudItem& rhs)
    : MudObject(rhs)
    , weight(rhs.weight)
    , type(rhs.type)
{}


VISITOR_ACCEPT(MudItem)


int MudItem::getWeight() const { return weight; }


int MudItem::getType() const { return type; }


bool MudItem::canPickup(MudPlayer& player) {
    return !activateTrigger(MUDITEM_TRY_PICKUP, (MudMobile*) &player);
}


void MudItem::pickup() {
    visible = true;
	clearTrigger(MUDITEM_TRY_PICKUP);
    generateEvent(MUDITEM_PICKUP);
}


void MudItem::serialize(StringBuilder& buffer) const {
    buffer << type;
}


ItemDbFactory::ItemDbFactory(const ItemDb& db_, int id_)
	: db(db_)
	, id(id_)
{}

MudItem& ItemDbFactory::create() const {
	MudItem* newItem = db.create(id);
	return *newItem;	
}

